package com.vnp.cooking.adapter;

import java.util.ArrayList;
import java.util.Hashtable;

import com.vnp.cooking.R;
import com.vnp.cooking.adapter.DetailLoaiMonAdapter.ViewHolder;
import com.vnp.cooking.bean.ObjAttribute;
import com.vnp.cooking.utils.PreferenceHelper;
import com.vnp.cooking.utils.Utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DialogItemAdapter extends BaseAdapter {
	
	Context context;
	ArrayList<ObjAttribute> listItem;
	PreferenceHelper preferenceHelper;
 	
	public DialogItemAdapter(Context context, ArrayList<ObjAttribute> listItem) {
		super();
		this.context = context;
		this.listItem = listItem;
		preferenceHelper = new PreferenceHelper(context);
	}

	@Override
	public int getCount() {
		return listItem.size();
	}

	@Override
	public Object getItem(int position) {
		return listItem.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		View v = convertView;
		if (v==null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			v = inflater.inflate(R.layout.dialog_item, parent, false);
			holder = new ViewHolder();
			
			holder.txtTenItem = (TextView) v.findViewById(R.id.txt_ten_item);
			holder.icSeclected = (ImageView) v.findViewById(R.id.img_selected);
			
			holder.txtTenItem.setTypeface(Utils.getTypefaceRegular(context));
			
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		ObjAttribute item = listItem.get(position);
		
		holder.txtTenItem.setText(item.getName());
		
		if (item.getAlias().equals(preferenceHelper.getFilterChecked())) {
			holder.icSeclected.setVisibility(View.VISIBLE);
		} else {
			holder.icSeclected.setVisibility(View.GONE);
		}
		return v;
	}
	
	
	class ViewHolder {
		TextView txtTenItem;
		ImageView icSeclected;
	}
}
